//
//  SZZStatusListViewModel.swift
//  SZZweibo
//
//  Created by 申壮壮 on 16/8/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SZZStatusListViewModel: NSObject {
    
    lazy var dataArray:[SZZStatusViewModel] = [SZZStatusViewModel]()
  

}
extension SZZStatusListViewModel{
    
    func loadDate(finish:(isSucces: Bool)->()){
        
        
        SZZNetworkTools.sharedTools.homeLoadData({ (response)->() in
            
            guard let res = response?["statuses"] as? [[String: AnyObject]] else{
                
                finish(isSucces: false)
                return
            }
            
            //创建一个临时可变数组
            var tempArray:[SZZStatusViewModel] = [SZZStatusViewModel]()
            
            for dic in res{
                
                let status = SZZtatusModel(dict: dic)
                let statusViewModel = SZZStatusViewModel(statusModel: status)
                
                //添加模型
                tempArray.append(statusViewModel)
                
            }
            
            self.dataArray = tempArray
            finish(isSucces: true)
            
            }) { (error) in
                
                finish(isSucces: false)
        }
    }
    
    
}